// GrandiaX Mana Egg Table GeneratorDoc.h : interface of the CGrandiaXManaEggTableGeneratorDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_GrandiaXMANAEGGTABLEGENERATORDOC_H__2B2E37FA_30CB_4C15_A2F4_2FC529E8D623__INCLUDED_)
#define AFX_GrandiaXMANAEGGTABLEGENERATORDOC_H__2B2E37FA_30CB_4C15_A2F4_2FC529E8D623__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

typedef struct SpecialCommonInfo
{
    int SP;
    int Element;
    int Selection;
    int Target;
    int Area;
    SPECIAL_HEADER* Header;
    SPECIAL_DEF* Definition;
    SPECIAL_DETAIL* Detail;
    const SPECIAL_HEADER* StockHeader;
    const SPECIAL_DEF* StockDefinition;
    const SPECIAL_DETAIL* StockDetail;
    MOVE_SKILLUP* MoveSkillUp;
    const MOVE_SKILLUP* StockMoveSkillUp;
} SpecialCommonInfo;


class CGrandiaXManaEggTableGeneratorDoc : public CDocument
{
protected: // create from serialization only
    CGrandiaXManaEggTableGeneratorDoc();
    DECLARE_DYNCREATE(CGrandiaXManaEggTableGeneratorDoc)

    // Attributes
public:

    typedef enum READWRITE_COMPONENT
    {
        rwcNone = 0,
        rwcMagicTable = 1,
        rwcMagic = 2,
        rwcSkillBook = 4,
        rwcSpecials = 8,
        rwcCombis = 16,
        rwcAll = 0xFFFFFFFF
    } READWRITE_COMPONENT;

    const char* GetManaEggNames(int Egg) const;
    void GetManaEggNamesWithHint(int Egg, char* Name);

    const char* GetMagicNames(int Magic) const;

    int GetReorderedEggIndex(int Egg);
    int GetReorderedEggReflectedIndex(int Egg);

    int GetMagic(int Egg, int Magic) const;
    void SetMagic(int Egg, int Magic, int Value);

    bool InOriginalEgg(int Egg, int Magic) const;
    void SetManaEggsToOriginal(int Egg, int Magic);

    bool IsFinalKeyMagic(int Egg, int Magic) const;

    const char* GetSkillBookNames(int Book) const;
    const char* GetSkillRankNames(int Rank) const;

    int GetSkillBookRank(int Book) const;
    int GetSkillBookCapacity(int Book) const;
    int GetSkillBookCost(int Book) const;

    void SetSkillBookCapacity(int Book, int Cap);
    void SetSkillBookCost(int Book, int Cost);
    void SetSkillBookRank(int Book, int Rank);

    const char* GetSFNames(int Sf) const;

    MAGIC_INTERNAL_DATA* GetMagicDesc(int Magic);

    void SetMagicToOriginal(int Magic);

    void SetMagicDesc(int Magic, const MAGIC_INTERNAL_DATA* Desc);

    EFFECT_INTERNAL_DATA* GetMagicEffect(int Magic);
    SPECIAL_HEADER* GetMagicHeader(int Magic);

    const char* GetMagicFunctionNames(int Function) const;
    const char* GetElementNames(int Element) const;

    const char* GetReceiverName(int Receiver) const;
    const char* GetAreaName(int Area) const;

    const char* GetStatusNames(int Status) const;
    const char* GetStatesNames(int State) const;

    const char* GetMagicSpecialNames(int Special) const;

    int GetMagicMainFunction(int Magic) const;
    void SetMagicMainFunction(int Magic, int Function);

    void SetMagicElement(int Magic, int Element);

    int GetMagicStatus(int Magic, int Status) const;
    void SetMagicStatus(int Magic, int Status, int set);

    int GetMagicState(int Magic, int States) const;
    void SetMagicState(int Magic, int State, int set);

    int GetMagicSpecial(int Magic) const;
    void SetMagicSpecial(int Magic, int Special);

    bool GetItemName(int Item, char* Name) const;

    const char* GetCharacterName(int Character) const;   

    const char* GetSpecialName(int Character, int Index) const; 

    void GetSpecialCommonInfo(
        SpecialCommonInfo* SCI, int Character, int Index);

    void SetSpecialCommonInfo(
        const SpecialCommonInfo* SCI, int Character, int Index);

    void GetCombiCommonInfo(
        SpecialCommonInfo* SCI, int Section, int Index);

    void SetCombiCommonInfo(
        const SpecialCommonInfo* SCI, int Section, int Index);

    const char* GetCombiSectionName(int Section) const;   
    const char* GetCombiSectionMembers(int Section) const;   
    const char* GetCombiName(int Section, int Index) const;

    bool ReadFromGame(READWRITE_COMPONENT rwc = rwcAll);
    void WriteToGame(READWRITE_COMPONENT rwc = rwcAll);
    
    void ReloadStockData(READWRITE_COMPONENT rwc = rwcAll);

    static int SpecialFunctionToIndex(int Function);
    
    // Operations
public:

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CGrandiaXManaEggTableGeneratorDoc)
public:
    virtual BOOL OnNewDocument();
    virtual void Serialize(CArchive& ar);
    virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
    //}}AFX_VIRTUAL

    // Implementation
public:
    virtual ~CGrandiaXManaEggTableGeneratorDoc();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

public:

    void DumpLoad(CString& FileName);
    void DumpSave(CString& FileName);

    // For Develop Only
    void SaveToPatch(CString& FileName);
    void DumpMemory(CString& FileName);

    void DumpLoad(CFile* File);
    void DumpSave(CFile* File);

    void LoadFromPatch(CArchive& ar);
    void SaveToPatch(CArchive& ar);

    void ExportHtm(CString& FileName);

    void DumpLoadv2(CFile* File, int ver);

protected:

    static const SKILL_BOOK StockSkillBooks[7];

    MANAEGG_INTERNAL_TABLE Magics[42];
    SPECIAL_HEADER MagicHeader[81];
    MAGIC_INTERNAL_DATA MagicData[81];
    EFFECT_INTERNAL_DATA EffectData[81];
    SKILL_BOOK SkillBooks[7];

    SPECIAL_HEADER SpecialHeader[8*6]; // last one for dummy
    SPECIAL_DEF SpecialDef[216];
    SPECIAL_DETAIL SpecialDetail[245];

    MOVE_SKILLUP MoveSkillUp[8*5];

    SPECIAL_HEADER CombiHeader[62];
    SPECIAL_DEF CombiDef[245];
    SPECIAL_DETAIL CombiDetails[562];

    int SpecialDefIndex[8*5];
    int SpecialDetailIndex[8*5];

    int CombiHdrIndex[9*5];
    int CombiDefIndex[9*5];
    int CombiDetailIndex[9*5];

    BOOL HintInfoBuilded;

    unsigned short Checks[42][6];

    bool DiscardableEggs[42];
  
    void UpdateHintInfo();

    void FixLoadedMagicData();

    void UpdateSpecialStartInfos();
    void UpdateCombiStartInfos();

    // Generated message map functions
protected:
    //{{AFX_MSG(CGrandiaXManaEggTableGeneratorDoc)
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_GrandiaXMANAEGGTABLEGENERATORDOC_H__2B2E37FA_30CB_4C15_A2F4_2FC529E8D623__INCLUDED_)
